package org.glz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.glz.mapper.UserMapper;
import org.glz.pojo.User;
import org.glz.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService{

    @Resource
    private UserMapper  userMapper;
    @Override
    public List<User> search(String userName) {
        QueryWrapper<User> wrapper = Wrappers.query();
        wrapper.like(!StringUtils.isBlank(userName),"userName",userName);
        return userMapper.selectList(wrapper);
    }

    public Page<User> search(String userName, int current, int size){
        QueryWrapper<User> wrapper = Wrappers.query();
        wrapper.likeRight(!StringUtils.isBlank(userName),"userName",userName);
        Page<User> page = new Page<>(current,size);
        return  userMapper.findByUserName(page,wrapper);
    }

    public User searchByUserCode(String userCode){
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("user_code",userCode);
        return userMapper.selectOne(wrapper);
    }

}
